[broadway] Add helper for processing input at idle
authorAlexander Larsson <alexl@redhat.com>
Tue, 5 Apr 2011 08:43:04 +0000 (10:43 +0200)
committerAlexander Larsson <alexl@redhat.com>
Thu, 7 Apr 2011 08:03:16 +0000 (10:03 +0200)
gdk/broadway/gdkdisplay-broadway.c
gdk/broadway/gdkdisplay-broadway.h

index 261d1f22994dd9e874389d1610a6d98650cc2294..a63b755bc1b498d354cd78b70514c4a848dd8983 100644 (file)
@@ -304,12 +304,21 @@ parse_input (BroadwayInput *input)
 static gboolean
 process_input_idle_cb (GdkBroadwayDisplay *display)
 {
+  display->process_input_idle = 0;
   process_input_messages (display);
   return FALSE;
 }
 
 static void
-_gdk_broadway_display_read_all_input_nonblocking (GdkDisplay *display )
+queue_process_input_at_idle (GdkBroadwayDisplay *broadway_display)
+{
+  if (broadway_display->process_input_idle == 0)
+    broadway_display->process_input_idle =
+      g_idle_add_full (GDK_PRIORITY_EVENTS, (GSourceFunc)process_input_idle_cb, broadway_display, NULL);
+}
+
+static void
+_gdk_broadway_display_read_all_input_nonblocking (GdkDisplay *display)
 {
   GdkBroadwayDisplay *broadway_display;
   GInputStream *in;
@@ -375,15 +384,12 @@ _gdk_broadway_display_block_for_input (GdkDisplay *display, char op,
 {
   GdkBroadwayDisplay *broadway_display;
   BroadwayInputMsg *message;
-  gboolean queued_idle;
   gssize res;
   guint8 buffer[1024];
   BroadwayInput *input;
   GInputStream *in;
   GList *l;
 
-  queued_idle = FALSE;
-
   gdk_display_flush (display);
 
   broadway_display = GDK_BROADWAY_DISPLAY (display);
@@ -424,11 +430,7 @@ _gdk_broadway_display_block_for_input (GdkDisplay *display, char op,
     /* Since we're parsing input but not processing the resulting messages
        we might not get a readable callback on the stream, so queue an idle to
        process the messages */
-    if (!queued_idle)
-      {
-       queued_idle = TRUE;
-       g_idle_add_full (G_PRIORITY_DEFAULT, (GSourceFunc)process_input_idle_cb, display, NULL);
-      }
+    queue_process_input_at_idle (broadway_display);
   }
 }
 
index 54389f3a1351c6752024fe3b1ff1e8e5e8175df5..0440b08f0c602653b44940a0f6c21fd20766d5f1 100644 (file)
@@ -147,6 +147,7 @@ struct _GdkBroadwayDisplay
   guint32 saved_serial;
   BroadwayInput *input;
   GList *input_messages;
+  guint process_input_idle;
 
   guint64 last_event_time;